package Classes.GameViews.ViewScenes// ActionScript file
{
	import Classes.GameErrors.GameError;
	import Classes.GameViews.GameView;
	import Classes.Managers.M_GameScenes;
	
	import flash.display.DisplayObjectContainer;
	import flash.display.Sprite;

	/**
	 *游戏显示场景类 
	 * @author 葛增文
	 * 
	 */	
	public class ViewScene extends GameView
	{
		private var _layerBackground:Sprite;/*背景层*/
		private var _layerCommon:Sprite;/*一般显示层*/
		private var _layerEffect:Sprite;/*特效显示层*/
		private var _newGuidePanel:Sprite;/*新手指导层*/
		private var _layerPanel:Sprite;/*窗口层*/
		public function ViewScene():void
		{
			this.init();
		}
		
		private function init():void
		{
			this._layerBackground=new Sprite;
			this._layerCommon=new Sprite;
			this._layerEffect=new Sprite;
			this._layerPanel=new Sprite;
			this._newGuidePanel=new Sprite();
			this.addChild(this.layerBackground);
			this.addChild(this.layerCommon);
			this.addChild(this.layerEffect);
			this.addChild(this.newGuidePanel);
			this.addChild(this.layerPanel);
			M_GameScenes.instance.joinScene(this);
		}
		
		/**
		 *打开场景 
		 * 
		 */		
		public function open():void
		{
			M_GameScenes.instance.openScene(this);
		}
		
		/**
		 *关闭场景 
		 * 
		 */		
		public function close():void
		{
			if(this.parent)this.parent.removeChild(this);
		}
		
		/**
		 *复位显示层 
		 * @param typeStr 层名
		 * 
		 */		
		public function resetLayer(typeStr:String):void
		{
			var targetSprite:Sprite=this[typeStr] as Sprite;
			if(targetSprite)
			{
				while(targetSprite.numChildren)targetSprite.removeChildAt(0);
			}
			else
			{
				throw new GameError("该显示层不存在");
			}
		}
		
		/**
		 *复位所有显示层 
		 * 
		 */		
		public function reset():void
		{
			this.resetLayer("layerBackground");
			this.resetLayer("layerCommon");
			this.resetLayer("layerEffect");
			this.resetLayer("layerWindow");
		}
		
		/**
		 *释放场景 
		 * 
		 */		
		public function release():void
		{
			if(this.parent)this.parent.removeChild(this);
			this.reset();
			this._layerBackground=null;
			this._layerCommon=null;
			this._layerEffect=null;
			this._layerPanel=null;
			this._newGuidePanel=null;
		}

		/*getter & setter*/
		public function get layerBackground():Sprite
		{
			return _layerBackground;
		}

		public function get layerCommon():Sprite
		{
			return _layerCommon;
		}

		public function get layerEffect():Sprite
		{
			return _layerEffect;
		}

		public function get layerPanel():Sprite
		{
			return _layerPanel;
		}

		public function get newGuidePanel():Sprite
		{
			return _newGuidePanel;
		}


	}
}